package com.natalia.file.service.impl.minio;

import com.google.common.collect.Multimap;
import io.minio.*;
import io.minio.messages.Part;
import lombok.SneakyThrows;

import java.util.concurrent.CompletableFuture;

/**
 * @Author yang
 **/
public class BaseMinioClient extends MinioAsyncClient {

    public BaseMinioClient(MinioAsyncClient client) {
        super(client);
    }


    /**
     *
     * @param bucketName 存储桶
     * @param region 区域
     * @param objectName 文件名
     * @param headers 请求头信息
     * @param extraQueryParams 额外查询参数
     */
    @Override
    @SneakyThrows
    public CompletableFuture<CreateMultipartUploadResponse> createMultipartUploadAsync(String bucketName, String region, String objectName, Multimap<String, String> headers, Multimap<String, String> extraQueryParams){
        return super.createMultipartUploadAsync(bucketName, region, objectName, headers, extraQueryParams);
    }

    /**
     * 分片上传
     * @param bucketName 存储桶
     * @param region 区域
     * @param objectName 对象名(文件名称)
     * @param data 文件流
     * @param length 文件的长度
     * @param uploadId 上传ID
     * @param partNumber 分片编号
     * @param extraHeaders 额外消息头
     * @param extraQueryParams 额外查询参数
     */
    @Override
    @SneakyThrows
    public CompletableFuture<UploadPartResponse> uploadPartAsync(String bucketName, String region, String objectName, Object data, long length, String uploadId, int partNumber, Multimap<String, String> extraHeaders, Multimap<String, String> extraQueryParams){
        return super.uploadPartAsync(bucketName, region, objectName, data, length, uploadId, partNumber, extraHeaders, extraQueryParams);
    }

    /**
     * 完成分片上传，执行合并文件
     *
     * @param bucketName       存储桶
     * @param region           区域
     * @param objectName       对象名
     * @param uploadId         上传ID
     * @param parts            分片
     * @param extraHeaders     额外消息头
     * @param extraQueryParams 额外查询参数
     */
    @Override
    @SneakyThrows
    public CompletableFuture<ObjectWriteResponse> completeMultipartUploadAsync(String bucketName, String region, String objectName, String uploadId, Part[] parts, Multimap<String, String> extraHeaders, Multimap<String, String> extraQueryParams){
        return super.completeMultipartUploadAsync(bucketName, region, objectName, uploadId, parts, extraHeaders, extraQueryParams);
    }

    /**
     * 查询分片数据
     *
     * @param bucketName       存储桶
     * @param region           区域
     * @param objectName       对象名
     * @param uploadId         上传ID
     * @param extraHeaders     额外消息头
     * @param extraQueryParams 额外查询参数
     */
    @Override
    @SneakyThrows
    public CompletableFuture<ListPartsResponse> listPartsAsync(String bucketName, String region, String objectName, Integer maxParts, Integer partNumberMarker, String uploadId, Multimap<String, String> extraHeaders, Multimap<String, String> extraQueryParams){
        return super.listPartsAsync(bucketName, region, objectName, maxParts, partNumberMarker, uploadId, extraHeaders, extraQueryParams);
    }


}
